package  
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.media.SoundChannel;
	import flash.text.TextField;
	import flash.desktop.NativeApplication;
	import flash.system.Capabilities;
	import flash.events.Event;
	/**
	 * ...
	 * @author patsup
	 * 
	 * 		Draws cool background, and has buttons for load, high scores, info, back.
	 * 
	 * 		Interacts with Main (using mainRef) to switch between menus.
	 */
	public class StartMenu extends Menu 
	{
		//start menu image parameters
		private const SM_COLOR:int = 0xFFFF80;
		//private const SM_WIDTH:int = 800;
		//private const SM_HEIGHT:int = 480;
		
		//private const NEW_BUTTON_X_STARTLOC:int = 250;			//Button for New Game
		//private const NEW_BUTTON_Y_STARTLOC:int = 130;
		
		//private const LOAD_BUTTON_X_STARTLOC:int = 60;			//Button for Load Game
		//private const LOAD_BUTTON_Y_STARTLOC:int = 250;
		//private const INFO_BUTTON_X_STARTLOC:int = 40;			//Button for Info
		//private const INFO_BUTTON_Y_STARTLOC:int = 440;
		//private const HS_BUTTON_X_STARTLOC:int = 520;			//Button for High Score
		//private const HS_BUTTON_Y_STARTLOC:int = 250;
		//private const EXIT_BUTTON_X_STARTLOC:int = 750;			//Button for Exit Game
		//private const EXIT_BUTTON_Y_STARTLOC:int = 430;
		//
		private var txtLabel:TextField;				//label
		
		private var mainRef:Main;
		
		//private var newButton:StartMenuBtn;
		
		//private var loadButton:GenButton;
		//private var infoButton:GenButton;
		//private var highScoreButton:GenButton;
		//private var exitButton:GenButton;
		
		private var backGround:Title_BackGround;
		private var StartSound:ShipCreak;
		private var sounds:Array;
		private var musicChannel:SoundChannel;
		
		public function StartMenu(mainRef:Main) 
		{
			txtLabel = new TextField();
			this.mainRef = mainRef;
			
			//DrawBackground();
			backGround = new Title_BackGround();
			addChild(backGround);
			
			musicChannel = new SoundChannel();
			sounds = new Array();
			StartSound = new ShipCreak();
			playBGMusic();
			
			//newButton = new StartMenuBtn(NEW_BUTTON_X_STARTLOC, NEW_BUTTON_Y_STARTLOC, "New Game", NewBtnInputMouseClick);
			//loadButton = new StartMenuBtn(LOAD_BUTTON_X_STARTLOC, LOAD_BUTTON_Y_STARTLOC, "Start", LoadBtnInputMouseClick);
			//infoButton = new StartMenuBtn(INFO_BUTTON_X_STARTLOC, INFO_BUTTON_Y_STARTLOC, "Instructions", InfoBtnInputMouseClick);
			//highScoreButton = new StartMenuBtn(HS_BUTTON_X_STARTLOC, HS_BUTTON_Y_STARTLOC,
																						//"High Scores", HSBtnInputMouseClick);
			//exitButton = new StartMenuBtn(EXIT_BUTTON_X_STARTLOC, EXIT_BUTTON_Y_STARTLOC,
																						//"Exit Game", ExitBtnInputMouseClick);

			//loadButton = new GenButton(LOAD_BUTTON_X_STARTLOC, LOAD_BUTTON_Y_STARTLOC, ScrollButton, LoadBtnInputMouseClick, "Start");
			backGround.continue_button.addEventListener(MouseEvent.CLICK, LoadBtnInputMouseClick);
			//infoButton = new GenButton(INFO_BUTTON_X_STARTLOC, INFO_BUTTON_Y_STARTLOC, Coin, InfoBtnInputMouseClick, "Info");
			backGround.info_button.addEventListener(MouseEvent.CLICK, InfoBtnInputMouseClick);
			
			//exitButton = new GenButton(EXIT_BUTTON_X_STARTLOC, EXIT_BUTTON_Y_STARTLOC, Round_Button, ExitBtnInputMouseClick, "x");
			backGround.exit_button.addEventListener(MouseEvent.CLICK, ExitBtnInputMouseClick);
			
			//highScoreButton = new GenButton(HS_BUTTON_X_STARTLOC, HS_BUTTON_Y_STARTLOC, ScrollButton, HSBtnInputMouseClick, "Hi Scores");
			
			//addChild(loadButton);
			//addChild(infoButton);
			//addChild(highScoreButton);
			//addChild(exitButton);
			
			//InitImage();
		}
		
		//test function to test loading stuff/writing it to screen
		public function TestIfWorking(abc:String):void
		{
			txtLabel.appendText("\n" + abc);
		}
		
		//InitImage()
		//Initializes the image of the StartMenu
		protected override function InitImage():void
		{
			super.InitImage();
		}
		
		//NewBtnInputMouseClick()
		//called on new button mouse click
		//protected function NewBtnInputMouseClick():void
		//{
			//mainRef.ResetGame();
			//mainRef.DisplayNewRound(this);
		//}
		//LoadBtnInputMouseClick()
		//called on load button mouse click
		protected function LoadBtnInputMouseClick(e:MouseEvent):void
		{
			//mainRef.sounds.stopSnd(sounds[0]);
			mainRef.DisplayLoadMenu(this);
		}
		//InfoBtnInputMouseClick()
		//called on info button mouse click
		protected function InfoBtnInputMouseClick(e:MouseEvent):void
		{
			mainRef.DisplayInfoMenu(this);
		}
		//HSBtnInputMouseClick()
		//called on high score button mouse click
		protected function HSBtnInputMouseClick():void
		{
			mainRef.DisplayHighScores(this);
		}
		//ExitBtnInputMouseClick()
		//called on exit game button mouse click
		protected function ExitBtnInputMouseClick(e:MouseEvent):void
		{
			var OS:String = Capabilities.os;
			var isWindows:Boolean = OS.indexOf("Windows") == 0;
			if(!isWindows)NativeApplication.nativeApplication.exit();
			trace("isWindows: " + isWindows);
			
		}
		/*
		private function DrawBackground():void 
		{
			graphics.beginFill(SM_COLOR);
			graphics.drawRect(0, 0, mainRef.stage.stageWidth, mainRef.stage.stageHeight);
			graphics.endFill();
			
			txtLabel.text = "Start Menu";
			addChild(txtLabel);
			
			
			
			var _bgShipImg:Big_Ship = new Big_Ship();
			var _ratio:Number = _bgShipImg.width / _bgShipImg.height;
			_bgShipImg.height = 180;
			_bgShipImg.width = _bgShipImg.height * _ratio;
			_bgShipImg.x = 360;
			_bgShipImg.y = 370;
			
			var _bgLogo:Logo = new Logo();
			_bgLogo.x = (mainRef.stage.stageWidth - _bgLogo.width)/2;
			_bgLogo.y = 10;
			addChild(_bgShipImg);
			addChild(_bgLogo);
			
			/*var _bgBird1:Bird_A = new Bird_A();
			var _bgBird2:Bird_B = new Bird_B();
			var _bgBird3:Bird_C = new Bird_C();
			var _bgBird4:Bird_D = new Bird_D();
			_bgBird1.x = 30;
			_bgBird1.y = 50;
			_bgBird2.x = 30;
			_bgBird2.y = 100;
			_bgBird3.x = 30;
			_bgBird3.y = 150;
			_bgBird4.x = 30;
			_bgBird4.y = 200;
			addChild(_bgBird1);
			addChild(_bgBird2);
			addChild(_bgBird3);
			addChild(_bgBird4);
			
		}*/
	public function playBGMusic():void
		{
			musicChannel = StartSound.play();
			musicChannel.addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
		}

		public function loopBGMusic(e:Event):void
		{
			if (musicChannel != null)
			{
				musicChannel.removeEventListener(Event.SOUND_COMPLETE, loopBGMusic);
				playBGMusic();
			}
		}
		
		}
	
	

		
}